You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Job Object protection has been added to prevent child processes spawned in Windows from remaining active when the parent crashes.
isolated-command.ts — Using Bun.FFI, CreateJobObjectW, AssignProcessToJobObject, and SetInformationJobObject are called via kernel32.dll. Thanks to the JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag, Windows automatically cleans up the child process when the parent dies. If FFI cannot be found, it silently falls back.
run-terminal-command.ts — After spawning, protectChildWithJob(pid) is called, and cleanup is triggered on the process close event.
Good instinct — orphaned child processes on Windows when the parent crashes/gets taskkill /F'd is a real, annoying bug, and Job Objects with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE are the correct fix.
The implementation has a critical bug though. In isolated-command.ts, limitInfo is allocated as Buffer.alloc(48) and 48 is passed as the length to SetInformationJobObject. On 64-bit Windows, JOBOBJECT_BASIC_LIMIT_INFORMATION is actually 64 bytes (two LARGE_INTEGER fields, DWORD LimitFlags at offset 16, then padding + two 8-byte SIZE_T fields + DWORD ActiveProcessLimit + padding + 8-byte ULONG_PTR Affinity + two more DWORDs = 64 bytes total). SetInformationJobObject validates the buffer length against the expected size for the information class and will reject a 48-byte buffer with ERROR_INVALID_PARAMETER. Because the code treats that failure as "gracefully unsupported" (if (!limitOk) { CloseHandle; return null }), the feature will silently never activate on essentially all real 64-bit Windows machines — exactly the case this PR is trying to fix. Worth fixing the struct size (and probably testing against GetLastError() during development to confirm the call actually succeeds, since the current fallback path masks this kind of failure).
Other things a maintainer will want before porting:
No tests. This is exactly the kind of platform-specific, hand-packed-struct code that benefits from a mocked-FFI unit test asserting the buffer layout/size.
The MSYS disable_pcon env var change in run-terminal-command.ts is bundled into the same PR but is unrelated to Job Object protection — worth splitting out with its own justification/repro.
require('bun:ffi') assumes a Bun runtime; confirm that's a fair assumption everywhere runTerminalCommand is invoked.
Solid direction, but the core mechanism needs to actually work before it's portable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bot:triagedClassified by the community triage botpr:needs-workRight idea, not mergeable as written
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Job Object protection has been added to prevent child processes spawned in Windows from remaining active when the parent crashes.